import Request from "@/common/utils/request/index";
import { ProductAttributeDto } from "@/types/model/product/dtos/productAttribute.dto";
import { Attribute } from "@/types/model/product/vos/attributes.vo";

enum Api {
  GetAllAttributes = "/jeecgboot/posAttributes/getAllAttributes",
  GetProductAttributes = "/jeecgboot/posAttributes/list",
  CreateProductAttribute = "/jeecgboot/posAttributes/createProductAttribute",
  EditProductAttribute = "/jeecgboot/posAttributes/edit",
  GetValuesByAttrId = "/jeecgboot/posAttributeValue/getValuesByAttrId",
  CreateAttrValue = "/jeecgboot/posAttributeValue/add",
  EditAttrValue = "/jeecgboot/posAttributeValue/edit",
  GetAttributeByProductId = "/jeecgboot/posAttributes/getAttributesByProductId",
}

export const getAllAttributes = () => {
  return Request.getInstance().send<any>({
    url: Api.GetAllAttributes,
    method: "GET",
  });
};

export const getProductAttributes = (params: any) => {
  return Request.getInstance().send<any>({
    url: Api.GetProductAttributes,
    method: "GET",
    params,
  });
};

export const createProductAttribute = (params: ProductAttributeDto) => {
  return Request.getInstance().send<void>({
    url: Api.CreateProductAttribute,
    method: "POST",
    data: params,
  });
};

export const getValuesByAttrId = (attrId: string) => {
  return Request.getInstance().send<any>({
    url: Api.GetValuesByAttrId,
    method: "GET",
    params: { attrId },
  });
};

export const getAttributeByProductId = (productId: string) => {
  return Request.getInstance().send<Attribute[]>({
    url: Api.GetAttributeByProductId,
    method: "GET",
    params: { productId },
  });
};

export const createAttrValue = (params: any) => {
  return Request.getInstance().send<any>({
    url: Api.CreateAttrValue,
    method: "POST",
    data: params,
  });
};

export const editAttrValue = (params: any) => {
  return Request.getInstance().send<any>({
    url: Api.EditAttrValue,
    method: "POST",
    data: params,
  });
};

export const editProductAttribute = (params: any) => {
  return Request.getInstance().send<any>({
    url: Api.EditProductAttribute,
    method: "POST",
    data: params,
  });
};
